//
//  HUProgress.m
//  WebKit
//
//  Created by Mac on 16/3/16.
//  Copyright © 2016年 HY. All rights reserved.
//

#import "HUProgress.h"
@interface HUProgress (){
    CGRect _viewRect;
}
@property (nonatomic, strong) CAShapeLayer* shapeLayer;
@property (nonatomic, strong) UIBezierPath* bezier;
@end
@implementation HUProgress

- (instancetype)initWithFrame:(CGRect)frame withColor:(UIColor *)color {
    self = [super initWithFrame:frame];
    if (self) {
        _viewRect = frame;
        _shapeLayer = [CAShapeLayer layer];
        _shapeLayer.fillColor = [UIColor clearColor].CGColor;
//        _shapeLayer.fillColor = color.CGColor;

        _shapeLayer.frame = self.bounds;
        _shapeLayer.position = self.center;

        _shapeLayer.strokeColor = color.CGColor;
        _shapeLayer.strokeStart = 0;
        _shapeLayer.strokeEnd   = 0;
        _shapeLayer.lineWidth   = frame.size.height / 2;
        
//        _bezier = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        _bezier = [UIBezierPath bezierPath];
        _bezier.lineWidth = frame.size.height;
        [_bezier moveToPoint:CGPointMake(0, frame.size.height / 2)];
        [_bezier addLineToPoint:CGPointMake(frame.size.width, frame.size.height / 2)];
        [_bezier closePath];
        
        
        _shapeLayer.path = _bezier.CGPath;
        
        [self.layer addSublayer:_shapeLayer];
    }
    return self;
}

- (void)setHUProgress:(CGFloat)progressFloat {
    _shapeLayer.strokeEnd = progressFloat / 2;
}
@end
